package com.codeduck.bean.entity;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;

/**
 * InstantiationAwareBeanPostProcessor: 为BeanPostProcessor的子类，用于Bean实例化前后处理。
 *
 * 向 Spring 注册 BeanLifeCycleVInstantiationAwareBeanPostProcessor :
 *      {@link com.codeduck.bean.config.BeanLifeCycleConfigV}
 *
 * @author: <a href="mailto:codeduck@163.com">Codeduck</a>
 * @createDate: 2021-12-23
 */
@Slf4j
public class BeanLifeCycleVInstantiationAwareBeanPostProcessor implements InstantiationAwareBeanPostProcessor {
    @Override
    public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
        if ("beanLifeCycleV".equals(beanName)) {
            log.warn("InstantiationAwareBeanPostProcessor#postProcessBeforeInstantiation 方法调用完毕");
        }
        return null;
    }

    @Override
    public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
        if ("beanLifeCycleV".equals(beanName)) {
            log.warn("InstantiationAwareBeanPostProcessor#postProcessAfterInstantiation 方法调用完毕");
        }
        return true;
    }

    @Override
    public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) throws BeansException {
        if ("beanLifeCycleV".equals(beanName)) {
            log.warn("InstantiationAwareBeanPostProcessor#postProcessProperties 方法调用完毕");
        }
        return pvs;
    }

}
